//
//  ActorListMainView.m
//  ProjectForCustomer
//
//  Created by 钟游 on 2019/8/28.
//  Copyright © 2019年 钟游. All rights reserved.
//

#import "ActorListMainView.h"
#import "LoginViewModel.h"
#import "SelectBtnView.h"
@interface ActorListMainView ()
{
    NSInteger count ;
    NSString * tagType;
    NSString * favouriteDirector;
}
@property(nonatomic,strong)LoginViewModel * viewModel;
@property(nonatomic,strong)CustomButton * eventBtn;
@property(nonatomic,strong)CustomButton * exchangeBtn;
@property(nonatomic,strong)CustomLabel * contentLabel;
@property(nonatomic,strong)CustomLabel * tipLabel;
@property(nonatomic,strong)SelectBtnView * btnView;
@property(nonatomic,strong)TagListModel * infoModel;
@end
@implementation ActorListMainView

-(instancetype)initWithViewModel:(id<ViewModelProtocol>)viewModel{
    self.viewModel =(LoginViewModel*)viewModel;
    return  [super initWithViewModel:viewModel];
}
-(void)zy_bindViewModel{
    @weakify(self);
    [[self.viewModel.weiSubject takeUntil:self.rac_willDeallocSignal]subscribeNext:^(id  _Nullable x) {
        @strongify(self);
        self->tagType =x;
        [self handleData];
    }];
    [[self.viewModel.tagListSubject takeUntil:self.rac_willDeallocSignal]subscribeNext:^(id  _Nullable x) {
        @strongify(self);
        if ([x isKindOfClass:[TagListModel class]]) {
            self.infoModel = x;
            self.btnView .baseDataArray =[NSMutableArray arrayWithArray:self.infoModel.tagInfoDetails] ;
        }
    }];
    [[self.viewModel.actorListSubject takeUntil:self.rac_willDeallocSignal]subscribeNext:^(id  _Nullable x) {
        [self.viewModel.qqSubject sendNext:nil];
    }];
}


-(void)zy_setupViews{
    count = 1;
    [self addSubview:self.eventBtn];
    [self addSubview:self.exchangeBtn];
    [self addSubview:self.contentLabel];
    [self addSubview:self.tipLabel];
    [self addSubview:self.btnView];
    self.btnView.selectBlock = ^(NSString * _Nonnull str) {
        self->favouriteDirector = str;
    };
}
#pragma mark -- 获取数据
-(void)handleData{
    NSDictionary * infoDict = @{@"tagType":@"2",
                                @"pageIndex":@(count),
                                @"pageSize":@(12)
                                
                                };
    [self.viewModel.tagListCommand execute:infoDict];
}
#pragma mark -- 下一批
-(void)exchangeBtnClick{
    count ++ ;
    [self handleData];
}
#pragma mark -- 下一步
-(void)eventBtnClick{
    NSDictionary * dict =@{@"favouriteDirector":favouriteDirector};
    [self.viewModel.actorListCommand execute:dict];
}
#pragma mark -- lazy
-(LoginViewModel *)viewModel{
    if (!_viewModel) {
        _viewModel=[[LoginViewModel alloc]init];
    }
    return _viewModel;
}
-(CustomButton *)eventBtn{
    if (!_eventBtn) {
        _eventBtn=[[CustomButton alloc]initWithFrame:CGRectMake(103.5, KscreenHeight-100-48, KscreenWidth-217, 48) andTitle:@"下一步" andColor:[UIColor whiteColor] andFont:18];
        _eventBtn.backgroundColor=UIColorFromRGB(0xFF5F57);
        _eventBtn.layer.cornerRadius=24;
        _eventBtn.layer.masksToBounds = YES;
        [_eventBtn addTarget:self action:@selector(eventBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _eventBtn;
}
-(CustomButton *)exchangeBtn{
    if (!_exchangeBtn) {
        _exchangeBtn=[[CustomButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.eventBtn.frame)+12, CGRectGetMidY(self.eventBtn.frame)-9.5, KscreenWidth-50-CGRectGetMaxX(self.eventBtn.frame)-12, 19) andTitle:@"换一批" andColor:[UIColor blackColor] andFont:13];
        [_exchangeBtn addTarget:self action:@selector(exchangeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _exchangeBtn;
}
-(CustomLabel *)contentLabel{
    if (!_contentLabel) {
        _contentLabel=[[CustomLabel alloc]initWithFrame:CGRectMake(0, HEIGHT_STATUSBAR_NAVBAR, KscreenWidth, 25) andText:@"选择最喜欢的导演" andFont:18 andColor:[UIColor blackColor]];
        _contentLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _contentLabel;
}
-(CustomLabel *)tipLabel{
    if (!_tipLabel) {
        _tipLabel=[[CustomLabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.contentLabel.frame)+10, KscreenWidth, 23) andText:@"（最多三个）" andFont:14 andColor:UIColorFromRGB(0x999999)];
        _tipLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _tipLabel;
}
-(SelectBtnView *)btnView{
    if (!_btnView) {
        _btnView=[[SelectBtnView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.tipLabel.frame)+10, KscreenWidth, CGRectGetMinY(self.eventBtn.frame)-CGRectGetMaxY(self.tipLabel.frame)-10) withDataArray:@[]];
    }
    return _btnView;
}

@end
